package com.fahai.web.service.impl;/**
 * Created by Lilinjun on 17/5/24.
 */

import com.fahai.common.PageVo;
import com.fahai.web.dao.SceneInfoDao;
import com.fahai.web.entity.SceneInfo;
import com.fahai.web.service.SceneInfoService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 场景和充值
 *
 * @author
 * @create 2017-05-24 下午4:05
 **/
@Service
@Transactional(rollbackFor = DataAccessException.class)
public class SceneInfoServiceImpl implements SceneInfoService {
    @Autowired
    SceneInfoDao dao;

    @Override
    public PageVo findSceneList(SceneInfo sceneInfo, PageVo pageVo) {
        Page<SceneInfo> page= PageHelper.startPage(pageVo.getPageNum(),pageVo.getPageSize());
        List<SceneInfo> vos = dao.select(sceneInfo);
        pageVo.setResult(vos);
        return pageVo;
    }

    /**
     * 更新场景
     *
     * @param sceneInfo
     */
    @Override
    public void update(SceneInfo sceneInfo) {
        dao.updateByPrimaryKeySelective(sceneInfo);
     //   map.put("ctype", 0);//0:微信1:app2:www3:html54:终端APPH5WWW0:公众号1:
      //  map.put("cobject", sceneInfo.getCobject());//场景性质 0 公益 1 商业
    }

    /**
     * 增加scene_info表记录
     *
     * @param sceneInfo
     */
    @Override
    public void add(SceneInfo sceneInfo) {
        if(sceneInfo.getCtype()==null){
            sceneInfo.setCtype(1);
        }
       dao.insertUseGeneratedKeys(sceneInfo);
    }

    @Override
    public int count(SceneInfo sceneInfo) {
       return  dao.selectCount(sceneInfo);
    }


    /**
     * 获取场景下拉列表
     * @param sceneInfo
     * @return
     */
    @Override
    public PageVo findSceneOptions(SceneInfo sceneInfo) {
        List<SceneInfo> vos=  dao.select(sceneInfo);
        PageVo pageVo=new PageVo();
        pageVo.setResult(vos);
        return pageVo;
    }
}
